package br.com.vepo.recipeondemand;

import android.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;


public class SearchByIngredients extends ActionBarActivity implements View.OnClickListener {
    private Button addButton ;
    private Button searchButton;
    private List<EditText> ingredientsTexts = new ArrayList<EditText>();
    private TableLayout ingredientsLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_by_ingredients);
        searchButton = (Button) findViewById(R.id.search_button);
        searchButton.setOnClickListener(this);

        addButton = (Button)findViewById(R.id.add_button);
        addButton.setOnClickListener(this);

        ingredientsTexts.add((EditText)findViewById(R.id.ingredient_0));
        ingredientsLayout  = (TableLayout) findViewById(R.id.ingredients_layout);

    }

    @Override
    public void onClick(View v) {
        if(v == addButton) {
            TableRow row = new TableRow(this);
            TableLayout.LayoutParams params = new TableLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

            row.setLayoutParams(params);

            TextView label = new TextView(this);
            label.setText((ingredientsTexts.size()+1) + ":");
            TableRow.LayoutParams labelParams = new TableRow.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            labelParams.column = 0;
            label.setLayoutParams(labelParams);
            row.addView(label);

            EditText ingredient = new EditText(this);
            TableRow.LayoutParams ingredientsParams = new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            ingredientsParams.column = 1;
            ingredient.setLayoutParams(ingredientsParams);
            row.addView(ingredient);
            ingredientsLayout.addView(row, ingredientsTexts.size());
            ingredientsTexts.add(ingredient);
            ingredient.requestFocus();
        }else if(v == searchButton){

        }
    }

//    @Override
//    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
//        getMenuInflater().inflate(R.menu.menu_search_by_ingredients, menu);
//        return true;
//    }

//    @Override
//    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
 //       int id = item.getItemId();

        //noinspection SimplifiableIfStatement
  //      if (id == R.id.action_settings) {
  //          return true;
  //      }

//        return super.onOptionsItemSelected(item);
 //   }
}
